package com.asktgapp.user.fragment;

import android.os.Bundle;
import android.support.annotation.IdRes;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RadioGroup;
import android.widget.TextView;

import com.asktgapp.R;
import com.asktgapp.base.BaseFragment;
import com.asktgapp.modulebase.common.util.PreferencesUtil;
import com.asktgapp.user.activity.MainActivity;
import com.umeng.commonsdk.debug.I;

import butterknife.ButterKnife;
import butterknife.InjectView;

/**
 * 我的咨询 ---付费咨询页面
 */

public class PayConsultFragment extends BaseFragment {
    @InjectView(R.id.group)
    RadioGroup mRadioGroup;
    @InjectView(R.id.viewpager)
    ViewPager mViewPager;

    @InjectView(R.id.myBack)
    TextView myBack;
    @InjectView(R.id.myToolbarRight)
    TextView myToolbarRight;
    private MyPagerAdapter mAdapter;


    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        ViewGroup viewGroup = (ViewGroup) inflater.inflate(R.layout.fragment_consult, container, false);
        ButterKnife.inject(this, viewGroup);

        return super.onCreateView(inflater, viewGroup, savedInstanceState);
    }

    @Override
    protected void initView(View rootView) {

        if (!PreferencesUtil.getBoolean(getActivity(), PreferencesUtil.KEY_IS_ENGINEER)) {
            myBack.setVisibility(View.INVISIBLE);
        }else {
            getBaseActivity().getToolbar().setVisibility(View.GONE);
        }
        mAdapter = new MyPagerAdapter(getChildFragmentManager());
        mViewPager.setAdapter(mAdapter);
        mViewPager.setCurrentItem(0);
        mViewPager.setOffscreenPageLimit(2);
        mRadioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, @IdRes int checkedId) {
                int position = group.indexOfChild(group.findViewById(checkedId));
                mViewPager.setCurrentItem(position);
            }
        });

        myBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                getBaseActivity().onBackPressed();
            }
        });

    }


    @Override
    public void loadData() {

    }


    @Override
    public void onDestroyView() {
        super.onDestroyView();

        ButterKnife.reset(this);
    }

    public class MyPagerAdapter extends FragmentPagerAdapter {

        public MyPagerAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int position) {
            switch (position) {
                case 0:
                    return PayConsultItemFragment.newInstance(0);
                case 1:
                    return PayConsultItemFragment.newInstance(1);
                default:
                    return PayConsultItemFragment.newInstance(0);
            }

        }

        @Override
        public int getCount() {
            return 2;
        }
    }


    @Override
    public void onResume() {
        super.onResume();
    }
}
